const wxHttpHandler = require('../../utils/wxHttpHandler.js');
const api = require('../../APIConfig/apiConfig.js');

Page({
  data: {
    licenseNo: '',
    registrationNo: '',
    transportPermits: ''
  },
  onShow: function () {},

  licenseNoInput: function (e) {
    this.setData({
      licenseNo: e.detail.value
    })
  },

  registrationNoInput: function (e) {
    this.setData({
      registrationNo: e.detail.value
    })
  },

  transportPermitsInput: function (e) {
    this.setData({
      transportPermits: e.detail.value
    })
  },

  submit: function () {
    this.addVehicle()
  },


  //添加车辆
  addVehicle: function () {

    if (this.data.licenseNo == '') {
      wx.showToast({
        title: '请输入经营许可证号',
      })
      return
    }

    if (this.data.registrationNo == '') {
      wx.showToast({
        title: '请输入车牌号',
      })
      return
    }

    if (this.data.transportPermits == '') {
      wx.showToast({
        title: '请输入道路运输许可证号',
      })
      return
    }


    let data = {
      uid: wx.getStorageSync('id'),
      LicenseNo: this.data.licenseNo,
      registrationNO: this.data.registrationNo,
      transportPermits: this.data.transportPermits
    }
    const that = this
    wx.showLoading()
    wxHttpHandler({
      type: 'get',
      path: api.addVehicle,
      data: data,
      fn: function (res) {
        wx.hideLoading()
        if (res.code == 0) {
          wx.showToast({
            title: res.data,
          })
        } else {
          wx.showToast({
            title: res.desc,
            icon: 'none',
            duration: 1500,
            mask: true
          });
        }
      }

    })
  },
})